package cn.uexpo.lhz.hxx;


import org.springframework.beans.factory.annotation.Autowired;
import cn.uexpo.lhz.feign.TestFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Random;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName HuangXiangXiang
 * @Date 2020/6/13 17:22
 * @Version V1.0
 *
 * 1、降级：限制每秒显示访问多少次
 * 2、熔断：A调用B B宕机超时的时候出现熔断机制
 **/

@RestController
@RefreshScope    //测试动态刷新配置
public class Controller {

    @Autowired
    MailSender mailSender;

    @Autowired
    private TestFeignService testFeignService;

//Value("${spring.application.pwd}")
  //  private String SpringApplicationPwd;

    @RequestMapping("/hxx")
    public List<Integer> hxx() throws InterruptedException {
//        Thread.sleep(10000);
        System.out.println("本地");
        List<Integer> integers = testFeignService.listA();

        return integers;
    }


@GetMapping("/test")
    public String test(){
        //生成随机验证码
        String checkCode = String.valueOf(new Random().nextInt(899999) + 100000);
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("15994054231@163.com");
        message.setTo("1477227147@qq.com");
        message.setSubject("门禁系统找回密码——系统邮件");
        message.setSentDate(new Date());
        message.setText("您正在修改您的密码，本次验证码为：" + checkCode + "\n 如非本人操作，请忽略！谢谢"+"http://127.0.0.1:8080/");
        mailSender.send(message);
        System.out.println("邮件发送成功");
        return checkCode;
    }


}
